﻿using LXYYY.IUserService;
using LXYYY.Models;
using LXYYY.UserDTO;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace LXYYY.UserService
{
    public class UserInformationService : CrudAppService<MyUserInformation, MyUserInformationShowDTO,int,PagedAndSortedResultRequestDto, MyUserInformationAddDTO>, IUserInformationService
    {
        public UserInformationService(IRepository<MyUserInformation, int> repository) : base(repository)
        {

        }
        [HttpPost,Route("UserInfoAdd")]
        public async Task<int> UserInfoAdd(MyUserInformationShowDTO myUserInformationShowDTO)
        {
            var list = await this.Repository.InsertAsync(new MyUserInformation()
            {
                InformationAccount = myUserInformationShowDTO.InformationAccount,
                InformationBalace = myUserInformationShowDTO.InformationBalace,
                InformationCode = myUserInformationShowDTO.InformationCode,
                InformationIntegral = myUserInformationShowDTO.InformationIntegral,
                InformationName = myUserInformationShowDTO.InformationName,
                InformationNIckName = myUserInformationShowDTO.InformationNIckName,
                InformationPassword = myUserInformationShowDTO.InformationPassword,
                InformationPhone = myUserInformationShowDTO.InformationPhone,
                InformationSex = myUserInformationShowDTO.InformationSex,
                InformationStata = myUserInformationShowDTO.InformationStata
            });
            return 1;
        }
        [HttpGet]
        [Route("UserInfoLogin")]
        public async Task<MyUserInformationShowDTO> UserInfoLogin(int ids, string pwd)
        {
            var list = await this.Repository.GetListAsync();
            var slist = list.Where(x => x.Id == ids && x.InformationPassword == pwd).FirstOrDefault();
            if (slist!=null)
            {
                var s = new MyUserInformationShowDTO();
                s.Id = slist.Id;
                s.InformationAccount = slist.InformationAccount;
                s.InformationBalace = slist.InformationBalace;
                s.InformationCode = slist.InformationCode;
                s.InformationIntegral = slist.InformationIntegral;
                s.InformationName = slist.InformationName;
                s.InformationNIckName = slist.InformationNIckName;
                s.InformationPassword = slist.InformationPassword;
                s.InformationPhone = slist.InformationPhone;
                s.InformationSex = slist.InformationSex;
                s.InformationStata = slist.InformationStata;
                return s;
            }
            return null;
        }
    }
}
